﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using YioksPlanEditor.Models;
using YioksPlanEditor.Yioks;

namespace YioksPlanEditor.Tools
{
    public class FuctionTool
    {
        public static void InitSoftData()
        {
            //调试模式
            YioksVar.SoftCfg.IsDebug = true;

            #region 基本配置
            YioksVar.SoftCfg.BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            YioksVar.SoftCfg.RootDirectory = AppDomain.CurrentDomain.BaseDirectory + "Yioks";
            FileTool.Dir_Create(YioksVar.SoftCfg.RootDirectory);

            YioksVar.SoftCfg.SystemIdentifier = YioksTool.IsX86 ? 1 : 2;
            YioksVar.SoftCfg.SoftName = AppDomain.CurrentDomain.FriendlyName;
            YioksVar.SoftCfg.SoftDirectory = YioksVar.SoftCfg.RootDirectory + "\\Yioks-PlanEditor";
            YioksVar.SoftCfg.SoftExecutablePath = Application.ExecutablePath;
            YioksVar.SoftCfg.SoftResourceDirectory = YioksVar.SoftCfg.SoftDirectory + "\\Resource";
            YioksVar.SoftCfg.SoftVersion = VersionUtil.AssemblyFileVersion.ToString();
            FileTool.Dir_Create(YioksVar.SoftCfg.SoftDirectory);
            FileTool.Dir_Create(YioksVar.SoftCfg.SoftResourceDirectory);
            //update
            YioksVar.SoftCfg.UpdateSoftName = "Yioks-Update.exe";
            YioksVar.SoftCfg.UpdateSoftDirectory = YioksVar.SoftCfg.RootDirectory + "\\Yioks-Update";
            YioksVar.SoftCfg.UpdateSoftExecutablePath = YioksVar.SoftCfg.UpdateSoftDirectory + "\\" +
                                                        YioksVar.SoftCfg.UpdateSoftName;
            FileTool.Dir_Create(YioksVar.SoftCfg.UpdateSoftDirectory);
            FileTool.Dir_Create(YioksVar.SoftCfg.UpdateSoftResourceDirectory);
  

            YioksVar.SoftCfg.MainSoftDirectory = YioksVar.SoftCfg.RootDirectory;
            //YioksVar.SoftCfg.MainSoftDirectory = YioksVar.SoftCfg.RootDirectory + "\\Yioks-Editor";
            YioksVar.SoftCfg.MainSoftName = "UnityPlayer.dll";
            FileTool.Dir_Create(YioksVar.SoftCfg.MainSoftDirectory);

            #endregion

            if (File.Exists(YioksVar.SoftCfg.RootDirectory + "\\softversion.xml"))
            {
                YioksVar.SoftVersionInfo.ParseCfgXml(YioksVar.SoftCfg.RootDirectory + "\\softversion.xml");
            }
            else
            {
                YioksVar.SoftVersionInfo.ExportXml(YioksVar.SoftCfg.RootDirectory + "\\softversion.xml");
            }

            YioksVar.SoftVersionInfo.SetFormVersion(VersionUtil.AssemblyFileVersion.ToString());
        }

    }
}
